package cn.zxf.note.note.type;

import cn.zxf.note.common.web.AbstractController;
import cn.zxf.note.note.type.dto.NoteTypeDto;
import cn.zxf.note.note.type.dto.NoteTypeStatisticsDto;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.server.ServerWebExchange;

import java.util.List;

@RestController
@RequestMapping("/api/note/type")
public class NoteTypeController extends AbstractController {

    @Autowired
    private NoteTypeService service;

    @GetMapping("find-all")
    public List<NoteTypeDto> findAll(
            ServerWebExchange ex
    ) {
        return service.findAll(super.curUserId(ex));
    }

    @GetMapping("statistics")
    public List<NoteTypeStatisticsDto> statistics(
            ServerWebExchange ex
    ) {
        return service.statistics(super.curUserId(ex));
    }

    @PostMapping("save")
    public NoteTypeDto save(
            ServerWebExchange ex,
            @RequestBody NoteTypeDto dto
    ) {
        return service.save(super.curUserId(ex), dto);
    }

    @DeleteMapping("delete/{typeId}")
    public NoteTypeDto delete(
            ServerWebExchange ex,
            @PathVariable Integer typeId
    ) {
        return service.delete(super.curUserId(ex), typeId);
    }

}
